package com.lxp.modules.gyy.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lxp.modules.gyy.domain.HrEmployee;
import com.lxp.modules.gyy.domain.ProjectTask;
import com.lxp.modules.gyy.domain.vo.EmpParam;
import com.lxp.modules.gyy.mapper.HrEmployeeMapper;
import com.lxp.modules.gyy.service.HrEmployeeService;
import com.lxp.modules.gyy.service.ProjectTaskService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author Administrator
 * @description 针对表【hr_department(Department)】的数据库操作Service实现
 * @createDate 2024-02-29 11:35:10
 */
@Service
public class HrEmployeeServiceImpl extends ServiceImpl<HrEmployeeMapper, HrEmployee> implements HrEmployeeService {

    @Resource
    private ProjectTaskService projectTaskService;

    @Override
    public List<HrEmployee> getList(EmpParam param) {
        LambdaQueryWrapper<HrEmployee> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(HrEmployee::getActive, true);
        Date startDate = param.getStartDate();
        Date endDate = param.getEndDate();
        Integer deptId = param.getDeptId();
        String empName = param.getEmpName();
        wrapper.eq(HrEmployee::getDepartmentId, deptId);

        if (StrUtil.isNotBlank(empName)) {
            wrapper.like(HrEmployee::getName, empName);
        }
        List<HrEmployee> employeeList = this.baseMapper.selectList(wrapper);
        return employeeList.stream().peek(e -> {
            List<ProjectTask> list = projectTaskService.getListByUserId(e.getUserId(),startDate,endDate);
            e.setTasks(list);
        }).collect(Collectors.toList());
    }
}




